package com.example.web;

import com.example.until.Example;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.util.UUID;

/**
 * Created by Administrator on 2017/9/11 0011.
 */
@Controller
public class DemoController {
    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("name","helloworld");
        return "/hello";
    }
    @RequestMapping("/getQrcode")
    public ResponseEntity<byte[]> getQrcode (Model model,HttpServletRequest request){
        String path = request.getContextPath();
        System.out.println("path"+path);
        model.addAttribute("path",path);
        String text = UUID.randomUUID().toString();
        System.out.println("text"+text);
        int width = 200;    //二维码图片的宽
        int height = 200;   //二维码图片的高
        String format = "png";  //二维码图片的格式
        try {
           return Example.generateQRCode(text, width, height, format);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
